// ====================================================================================
// RibbonTableCache.cs
//
// Created by: NI, 2007.03.27
// Revised by: NI, 2007.11.23
// ====================================================================================
using System.Collections.Generic;

namespace RibbonExplorer.Storage
{
  // ====================================================================================
  /// <summary>
  /// This class is a singleton for storing ribbon tables in a cache.
  /// </summary>
  // ====================================================================================
  public static class RibbonTableCache
  {
    private static readonly Dictionary<string, RibbonTable> _Cache = new Dictionary<string, RibbonTable>();

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// This static consstructor sets up the ribbon table cache.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    static RibbonTableCache()
    {
      Setup();
    }

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Clears the content of the cache.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public static void Clear()
    {
      _Cache.Clear();
    }

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Reads the specified ribbon table into the cache.
    /// </summary>
    /// <param name="id">Ribbon table ID</param>
    // --------------------------------------------------------------------------------------------
    public static void Read(string id)
    {
      RibbonTable newTable = new RibbonTable(id);
      newTable.ReadTable();
      _Cache.Add(id, newTable);
    }

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Gets the ribbon table from the cache.
    /// </summary>
    /// <param name="id">Ribbon table ID</param>
    /// <param name="table">Output parameter for the ribbon table</param>
    /// <returns>
    /// True, if the table has benn found in the cache; otherwise, false;
    /// </returns>
    // --------------------------------------------------------------------------------------------
    public static bool TryGetValue(string id, out RibbonTable table)
    {
      return _Cache.TryGetValue(id, out table);
    }

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Sets up the ribbon table by loading all tables into this cache.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public static void Setup()
    {
      Clear();

      // --- Load simple ribbons
      Read("AccessRibbon");
      Read("ExcelRibbon");
      Read("PowerPointRibbon");
      Read("WordRibbon");

      // --- Load Outlook ribbons
      Read("AddressItemRibbon");
      Read("AppointmentItemRibbon");
      Read("DistributionListItemRibbon");
      Read("JournalItemRibbon");
      Read("MailComposeItemRibbon");
      Read("MailReadItemRibbon");
      Read("MeetingCounterProposeItemRibbon");
      Read("MeetingRequestComposeItemRibbon");
      Read("MeetingRequestReadItemRibbon");
      Read("MeetingResponseComposeItemRibbon");
      Read("MeetingResponseReadItemRibbon");
      Read("PostItemRibbon");
      Read("PostReadItemRibbon");
      Read("ReportItemRibbon");
      Read("ResendItemRibbon");
      Read("RSSItemRibbon");
      Read("SharingComposeItemRibbon");
      Read("SharingReadItemRibbon");
      Read("TaskItemRibbon");
    }
  }
}
